﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Resources;
using System.IO;

namespace luozhuang.Commons
{
    public class resMd5
    {
        /// <summary>
        /// 校验资源文件
        /// </summary>
        /// <param name="dlluri">dll的地址，如果是模块资源要用Uri("/模块名;component/路径", UriKind.Relative)</param>
        /// <param name="xapResource">xap的StreamResourceInfo，本地用null</param>
        /// <returns></returns>
        public static byte[] Md5Resource(Uri dlluri, StreamResourceInfo xapResource)
        {
            luozhuang.Commons.MD5CryptoServiceProvider cup = new luozhuang.Commons.MD5CryptoServiceProvider();
            byte[] md5byte;
            StreamResourceInfo dllStreamInfo;
            if (xapResource == null)
            {
                dllStreamInfo = Application.GetResourceStream(dlluri);
            }
            else
            {
                dllStreamInfo = Application.GetResourceStream(xapResource, dlluri);
            }
            using (Stream stream = dllStreamInfo.Stream)
            {
                md5byte = cup.ComputeHash(stream);
            }


            return md5byte;
        }
    }
}
